package com.fish.common.web;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fish.common.constant.Constant;
import com.fish.user.po.User;

public class SuperUserFilter implements Filter{
	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		
	}

	/** 
	 * 
	*/ 
	public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		HttpServletResponse res = (HttpServletResponse) response;
		System.out.println(req.getServletPath());
		if(req.getServletPath().indexOf("login")>0||req.getServletPath().indexOf("pay")>0) {
			chain.doFilter(req, res);
		} else {
			//验证是否登录
			User user = (User) req.getSession().getAttribute(Constant.SESSION_BACK_USER_KEY);
			if (user == null) {
				res.sendRedirect(req.getContextPath()+"/login.jsp");
			}else{
				chain.doFilter(req, res);
			}
		}
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
				
	}

}
